package service

import (
	"context"
	__ "shop-server/basic/proto"
	"shop-server/handler/model"
)

// server is used to implement helloworld.GreeterServer.
type Server struct {
	__.UnimplementedShopServer
}

// SayHello implements helloworld.GreeterServer
func (s *Server) ShopAdd(_ context.Context, in *__.ShopAddReq) (*__.ShopAddResp, error) {
	return &__.ShopAddResp{
		Code:    0,
		Message: "",
	}, nil
}

// SayHello implements helloworld.GreeterServer
func (s *Server) ShopStatus(_ context.Context, in *__.ShopStatusReq) (*__.ShopStatusResp, error) {

	status := model.Status{
		ShopId: int(in.ShopId),
		Status: int(in.Status),
		Reason: in.Reason,
	}

	if err := status.CreateStatus(); err != nil {
		return &__.ShopStatusResp{
			Code:    400,
			Message: "同步失败",
		}, nil
	}

	return &__.ShopStatusResp{
		Code:    200,
		Message: "商品状态同步成功",
	}, nil
}
